<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
<script src="../script/vue.js"></script>

<body>
    <component id="school">
        <h1>学校信息</h1>

        <h2>学校名称：{{schoolName}}</h2>
        <h2>学校地址：{{schoolAddress}}</h2>
        
        <hr/>

        <h1>学生信息</h1>
        <button @click="addSex">点击添加性别属性</button>
        <h2 v-if="student.sex">学生性别：{{student.sex}}</h2>
        <h2>学生姓名：{{student.name}}</h2>
        <h2>学生身份证：{{student.idCardNumber}}</h2>
    </component>

</body>
<script>
    Vue.config.devtools = true
    let data = [
        { 'name': '张三', 'age': 18, 'idCardNumber': '360122199590945252' },
        { 'name': '李四', 'age': 19, 'idCardNumber': '360122199590942462' },
        { 'name': '王五', 'age': 20, 'idCardNumber': '360122199590945246' },
        { 'name': '赵六', 'age': 15, 'idCardNumber': '360122199590945325' }
    ];
    let vue = new Vue({
        el: '#school',
        data:{
            schoolName: '北京大学',
            schoolAddress:'北京海淀区19802号',
            student:{
                name: '张三',
                age: 18,
                idCardNumber: '360122199590945252'
            }
        },
        methods: {
            addSex(){
                Vue.set(this.student, 'sex', '男');
            }
        }
    });
</script>

</html>